package com.ruoyi.bizsys.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.CreditAccount;
import com.ruoyi.bizsys.service.ICreditAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 授信账户Controller
 *
 * @author african-loan
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/bizsys/CreditAccount")
public class CreditAccountController extends BaseController {
    @Autowired
    private ICreditAccountService creditAccountService;

    /**
     * 查询授信账户列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(CreditAccount creditAccount) {
        startPage();
        List<CreditAccount> list = creditAccountService.selectCreditAccountList(creditAccount);
        return getDataTable(list);
    }

    /**
     * 导出授信账户列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:account:export')")
    @Log(title = "授信账户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CreditAccount creditAccount) {
        List<CreditAccount> list = creditAccountService.selectCreditAccountList(creditAccount);
        ExcelUtil<CreditAccount> util = new ExcelUtil<CreditAccount>(CreditAccount.class);
        return util.exportExcel(list, "account");
    }

    /**
     * 获取授信账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(creditAccountService.selectCreditAccountById(id));
    }

    /**
     * 新增授信账户
     */
    @PreAuthorize("@ss.hasPermi('bizsys:account:add')")
    @Log(title = "授信账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CreditAccount creditAccount) {
        return toAjax(creditAccountService.insertCreditAccount(creditAccount));
    }

    /**
     * 修改授信账户
     */
    @PreAuthorize("@ss.hasPermi('bizsys:c:edit')")
    @Log(title = "授信账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CreditAccount creditAccount) {
        return toAjax(creditAccountService.updateCreditAccount(creditAccount));
    }

    /**
     * 删除授信账户
     */
    @PreAuthorize("@ss.hasPermi('bizsys:account:remove')")
    @Log(title = "授信账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(creditAccountService.deleteCreditAccountByIds(ids));
    }
}
